package com.fz.us.oa.core.dao.com.impl;

import com.fz.us.admin.base.bean.BaseEnumManager;
import com.fz.us.admin.company.dao.impl.BaseFlowDaoImpl;
import com.fz.us.admin.company.entity.*;
import com.fz.us.oa.core.dao.com.PersonnelInfoDao;
import com.fz.us.oa.core.entity.com.PersonnelInfo;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by ZhuChunXiao on 2017/7/14.
 */
@Repository
public class PersonnelInfoDaoImpl extends BaseFlowDaoImpl<PersonnelInfo, String> implements PersonnelInfoDao {
    @Override
    public Power getPowerByDepartmentAndPost(Department department, Post post) {
        List<Power> powerList=getSession().createQuery("from Power p where p.department=? and p.post=? and p.state=?")
                .setParameter(0,department)
                .setParameter(1,post)
                .setParameter(2, BaseEnumManager.StateEnum.Enable)
                .list();
        if(powerList.size()>0){
            return powerList.get(0);
        }else{
            return null;
        }
    }

    @Override
    public List<Power> getPowerByDepartment(Department department) {
        List<Power> powerList=getSession().createQuery("from Power p where p.department=? and p.state=?")
                .setParameter(0,department)
                .setParameter(1, BaseEnumManager.StateEnum.Enable)
                .list();
        return powerList;
    }

    @Override
    public Duty getDutyByPowerAndUser(Power power, User user) {
        List<Duty> dutyList=getSession().createQuery("from Duty d where d.power=? and d.user=? and d.state=?")
                .setParameter(0,power)
                .setParameter(1,user)
                .setParameter(2,BaseEnumManager.StateEnum.Enable)
                .list();
        if(dutyList.size()>0){
            return dutyList.get(0);
        }else{
            return null;
        }
    }
}
